import xCalendar from 'comp/loan/calendar/calendar.vue'
import { mapState } from 'vuex'

var data = {
    detail: null
}

var vm = {
    data() {
        return data
    },
    computed: {
        ...mapState(['order', 'user']),
        loanDay() {
            if (this.order.orderDate) {
                var dateArr = this.order.orderDate.split('-')
                return {
                    year: dateArr[0],
                    month: Number(dateArr[1]) - 1,
                    date: dateArr[2]
                }
            } else {
                return null
            }
        },
        repayDay() {
            if (this.order.repayDate) {
                var dateArr = this.order.repayDate.split('-')
                return {
                    year: dateArr[0],
                    month: Number(dateArr[1]) - 1,
                    date: dateArr[2]
                }
            } else {
                return null
            }
        }
    },
    mounted() {
        $loading.show()
        $ajax.order.detail({
            userId: this.user.userId
        }).then(res => {
            var { code, msg, data } = res.data
            if (code == 'S') {
                $loading.hide()
                $store.commit('orderUpdate', data)
            } else {
                $toast.show(msg)
            }
        }).catch(err => {
            $loading.show()
            $router.replace('/system/neterror')
        })
    },
    methods: {
        // 还款
        repay() {
            $router.replace('/loan/repay')
        }
    },
    components: {
        xCalendar
    },
    mixins: [$mixins.needLogin]
}

export default vm